<template>
  <div class="page-carousel">
    <el-carousel indicator-position="outside" :height= "img_height + 'px'" type="card">
      <el-carousel-item v-for="item in imgList" :key="item.name">
        <img :src="item.url" alt="图片丢失" :title="item.title" @load="img_load" ref='img_ref'>
      </el-carousel-item>
    </el-carousel>
  </div>

</template>
<style scoped>


</style>

<script>
export default {
  name: "carousel",
  data(){
    return{
      imgList:[
        {
          name:"first",
          url:require("../assets/pixel-1.jpg"),
          title:"first"
        },
        {
          name:"second",
          url:require("../assets/pixel-2.jpg"),
          title:"second"
        },
        {
          name:"third",
          url:require("../assets/pixel-3.jpg"),
          title:"third"
        },
        {
          name:"fourth",
          url:require("../assets/pixel-4.jpg"),
          title:"fourth"
        }
      ],
      img_height:''

    }
  },
  methods:{
    img_load(){
      this.img_height = this.$refs.img_ref[0].height;
    }

  }
}
</script>

<style scoped>
.page-carousel{
  width: 100%;
  height:100%;
  padding-top:20px;
}
.el-carousel__item img {
  margin: 0 auto;
  width: 100%;
}


</style>
